#!/usr/bin/env python

import sys 
import string

def send_message(from_address, to_addresses, subject, body):
    import popen2
    # import smtplib
    #    body = 'From: ' + from_address + '\nTo: ' + string.join(to, ', ') \
    #           + '\nSubject: ' + subject + '\n\n' + body
    #    
    #    mailer = smtplib.SMTP('localhost')
    #    mailer.sendmail(from_address, to, body)
    #    mailer.quit
    
    # sendmail options:
    # -od = delivery mode, where d is one of:
    #        q = queue
    #        b = background
    #        i = interactive (foreground)             
    # -oi =  ignore dots on lines by themselves ( I think )
    # -t  =  read message for recipients
    (mailout, mailin) = popen2.popen2("/usr/lib/sendmail -oi -t -odb")
    mailout.close()
    mailin.write('To: ' + string.join(to_addresses, ', ') + '\n'
                 'MIME-Version: 1.0\n'
                 'Content-Type: text/html;\n'
                 'Subject: '+ subject + '\n\n'
                 + body)
    mailin.close()
# fed send_message

def do_main():

    body = '''
<html>
<body>
<h1>This is a message</h1>
<p>And it goes on....</p>
<IMG BORDER=0 SRC="http://internal/~bconrad/Images/Bars/hippo_start.gif">
</body>
</html>
    '''


    send_message('bconrad@aqua.mitra.com',
                 ['bconrad@aqua.mitra.com', 'drahn@aqua.mitra.com'],
                 'test',
                 body)

# fed do_main


if  __name__ == '__main__':
    do_main()
